package com.aiguigu.safe;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

public class ListNotSafeDemo {
    public static void main(String[] args) {
       //ArrayList是线程不安全的
//        List<String> list = new ArrayList<>();
        List<String> list = new Vector<>();



      //给ArrayList加锁  线程安全了
//        List<String> list = Collections.synchronizedList(new ArrayList<>());

//  CopyOnWriteArrayList 读写分离 写时复制
//        List<String> list = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(0,6));
                System.out.println(list);
            },String.valueOf(i)).start();
        }


    }
}
